package com.ruoyi.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.config.SensitiveWordConfig;
import com.ruoyi.domain.T18;
import com.ruoyi.domain.vo.TestView;
import com.ruoyi.filter.SensitiveWordFilter;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.service.IT06Service;
import com.ruoyi.service.IT18Service;
import com.ruoyi.system.service.impl.SysRoleServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.T22;
import com.ruoyi.service.IT22Service;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 111111Controller
 *
 * @author ruoyi
 * @date 2025-04-05
 */
@RestController
@RequestMapping("/system/T22")
@Api(tags = "敏感词管理")
public class T22Controller extends BaseController
{
    @Autowired
    private IT22Service t22Service;

    @Autowired
    private TokenService tokenService;
    @Autowired
    private IT18Service t18Service;
    @Autowired
    private SysRoleServiceImpl sysRoleService;

    @Autowired
    private SensitiveWordConfig sensitiveWordConfig;
    /**
     * 查询111111列表
     */

    @GetMapping("/list")
    @Log(title = "敏感词")
    @ApiOperation(value = "查询敏感词列表")
    public TableDataInfo list(T22 t22,HttpServletRequest request)
    {
        LoginUser loginUser = tokenService.getLoginUser(request); // 确保tokenService和getLoginUser方法存在
        Long userId = loginUser.getUserId();
        List<Long> longs = sysRoleService.selectRoleListByUserId(userId);
        Long roleId = longs.get(0);
        if(roleId==100){
            Long F0301 = t18Service.selectF0301ByF1801(userId);
            t22.setF0301(F0301);
        }
        List<T22> list = t22Service.selectT22List(t22);
        return getDataTable(list);
    }

    /**
     * 导出111111列表
     */

    @Log(title = "敏感词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")

    public void export(HttpServletResponse response, T22 t22)
    {
        List<T22> list = t22Service.selectT22List(t22);
        ExcelUtil<T22> util = new ExcelUtil<T22>(T22.class);
        util.exportExcel(response, list, "111111数据");
    }

    /**
     * 获取111111详细信息
     */

    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(t22Service.selectT22ByID(ID));
    }

    /**
     * 新增111111
     */
    @Autowired
    private SensitiveWordFilter sensitiveWordFilter;

    @Log(title = "敏感词", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增敏感词")
    @PostMapping
    public AjaxResult add(@RequestBody T22 t22,HttpServletRequest request)
    {
        LoginUser loginUser = tokenService.getLoginUser(request);
        Long userId = loginUser.getUserId();
        T18 t18 = t18Service.selectT18ByF1801(userId);
        Long F0301 = t18.getF0301();
        t22.setCreateDate(new Date());
        t22.setCreateBy(t18.getF1804());
        t22.setUpdateDate(new Date());
        t22.setUpdateBy(t18.getF1804());
        t22.setF0301(F0301);
        sensitiveWordFilter.getSenWord(request,2);
        return toAjax(t22Service.insertT22(t22));
    }

    /**
     * 修改111111p
     */

    @ApiOperation(value = "修改敏感词")
    @Log(title = "敏感词", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody T22 t22,HttpServletRequest request)
    {
        t22Service.updateT22(t22);
        sensitiveWordFilter.getSenWord(request,2);
        return AjaxResult.success("修改成功");
    }

    /**
     * 删除111111
     */

    @Log(title = "敏感词", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除敏感词")
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs,HttpServletRequest request)
    {
        t22Service.deleteT22ByIDs(IDs);
        sensitiveWordFilter.getSenWord(request,2);
        return AjaxResult.success("删除成功");
    }

    @ApiOperation(value = "视图查询")
    @GetMapping("/findAll")
    public AjaxResult findAll(HttpServletRequest request)
    {
        List<TestView> list = t22Service.findAllByView();
        return success(list);
    }
}
